Imports System.Xml.Serialization
Imports System.Collections.ObjectModel

Public MustInherit Class EntityPropertyBase
    Inherits XEntityModelElementWithDocumentationBase

    ''' <summary>Initializes an instance of the <see cref="XEntityModelElementBase" /> class.</summary>
    ''' <param name="localName">The local name of the new element.</param>
    ''' <param name="namespaceName">The name of the namespace of the new element.</param>
    Protected Sub New(ByVal localName As String, ByVal namespaceName As String)
        Me.New(New XElement(XName.Get(localName, namespaceName)))
    End Sub

    ''' <summary>Initializes an instance of the <see cref="EntityPropertyBase" /> class.</summary>
    ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
    Protected Sub New(ByVal other As XElement)
        MyBase.New(other)
    End Sub

    ''' <summary>
    ''' Returns a value indicating if the property is a key.
    ''' </summary>
    ''' <returns><c>True</c> if the property is a key; <c>False</c> otherwise.</returns>
    Public MustOverride Function IsKey() As Boolean

    ''' <summary>
    ''' Gets the <see cref="XNamespace"/> of this instance of the <see cref="EntityPropertyBase"/>.
    ''' </summary>
    Protected ReadOnly Property [Namespace]() As XNamespace
        Get
            Return MyBase.Name.Namespace
        End Get
    End Property

    <XmlAttribute()> _
    Public Shadows Property Name() As String
        Get
            Return Me.@Name
        End Get
        Set(ByVal value As String)
            Me.@Name = value
        End Set
    End Property

    <XmlAttribute()> _
    Public Property Type() As String
        Get
            Return Me.@Type
        End Get
        Set(ByVal value As String)
            Me.@Type = value
        End Set
    End Property

    <XmlAttribute(), _
     System.ComponentModel.DefaultValue(True)> _
    Public Property Nullable() As Boolean
        Get
            Return Me.@Nullable
        End Get
        Set(ByVal value As Boolean)
            Me.@Nullable = value
        End Set
    End Property

    <XmlAttribute()> _
    Public Property DefaultValue() As String
        Get
            Return Me.@DefaultValue
        End Get
        Set(ByVal value As String)
            Me.@DefaultValue = value
        End Set
    End Property

    <XmlAttribute()> _
    Public Property MaxLength() As Integer
        Get
            If (Me.@MaxLength = "Max") Then
                Return -1
            End If
            Return Me.@MaxLength
        End Get
        Set(ByVal value As Integer)
            If (value = -1) Then
                Me.@MaxLength = "Max"
            Else
                Me.@MaxLength = value
            End If
        End Set
    End Property

    <XmlAttribute()> _
    Public Property FixedLength() As Boolean
        Get
            Return Me.@FixedLength
        End Get
        Set(ByVal value As Boolean)
            Me.@FixedLength = value
        End Set
    End Property

    <XmlAttribute(DataType:="nonNegativeInteger")> _
    Public Property Precision() As Integer
        Get
            Return Me.@Precision
        End Get
        Set(ByVal value As Integer)
            Me.@Precision = value
        End Set
    End Property

    <XmlAttribute(DataType:="nonNegativeInteger")> _
    Public Property Scale() As Integer
        Get
            Return Me.@Scale
        End Get
        Set(ByVal value As Integer)
            Me.@Scale = value
        End Set
    End Property

    <XmlAttribute()> _
    Public Property [Unicode]() As Boolean
        Get
            Return Me.@Unicode
        End Get
        Set(ByVal value As Boolean)
            Me.@Unicode = value
        End Set
    End Property

    <XmlAttribute()> _
    Public Property Collation() As String
        Get
            Return Me.@Collation
        End Get
        Set(ByVal value As String)
            Me.@Collation = value
        End Set
    End Property

End Class
